<? if ($c = stack('name')) {

	$d = component_data($c);

	?><section id="cpn-<?=$c?>" class="cpn-register"><?

		if (gccLoggedIn()) {
			
			?><p><?=tc('You are already registered')?></p><?
			
		} else {
			
			startScript('jquery, jquery.validationEngine, jquery.validationEngine-'.context('lang').', other-validations-'.context('lang').', jquery.maskedinput.min, jquery.tools, jquery.linked_select, jquery.jstree, jquery.autocomplete, jquery.koatuudo, jquery.sbx');

			?><script type="text/javascript">
			//$( "#birthday" ).dateinput({format: 'dd.mm.yyyy', lang: '<?//=context('lang')?>', selectors: true, min: '1900-01-01', max: new Date(), firstDay: 1, yearRange: [-100,1]});
			

			var o = $("<div/>", {"class":"box modal overlay"}).appendTo($("body")).overlay({
				mask: { color: "#000", loadSpeed: 100, opacity: 0.5, zIndex: 99998 },
				top: "center", closeOnClick: false,	closeOnEsc: false
			}).on("click", ".close", function(){ o.overlay().close(); });
			
			var msg = { 
				plsWait: '<div class="message"><?=htc('Please wait')?></div><img class="loader" src="/img/ajax_loader_light.gif">',
				saved:'<div class="caption"><?=htc('Saved-caption')?></div><div class="message"><?=htc('Saved-text')?></div>' + 
					'<div class="footer"><input type="button" class="ok close" value="<?=htc('Saved-ok')?>"></div>'
			};
			
			$("#cpn-<?=$c?> form").validationEngine({
				ajaxFormValidation: true,
				onBeforeAjaxFormValidation: function(form, options){
					o.html(msg.plsWait).overlay().load();
				},
				onAjaxFormComplete: function ajaxValidationCallback(status, form, json, options){
				 
					if (status === true) {
						location.href = "/<?=$CONTEXT['lang_prefix']?>register/reg-sent/";
					} else {	// some error
						o.overlay().close();
					}
				}
			});


			$('[linked]').link_select({zero_string: '<?=$_magic?>', url: '/register/reg-p/get-koatuu/?id='})

			$("#fact_index").masked("99999");
			/* $("#contactphone, #contactphone2").mask("(999)999-9999"); */
			//$("#birthday").masked("99.99.9999");

			$('#koatuu').koatuudo({});

			
			</script><? endScript();
		
			?><form action="./" method="post">

				<h1><?=tc('Реєстрація фізичної особи')?></h1>
				<!--<p class="nb">(<?//=$_SESSION['reg']['email']?>)</p>-->
				<p class='nb'><?=tc("Символом <span class='required'>*</span> відмічені поля, обов'язкові для заповнення.")?></p>
				<fieldset>
					<!--<h2 class="legend"> <?//=tc('Personal data')?> </h2>-->
			
					<div class="inner">
						<label class="col1"><?=tc('Last Name')?><span class="required">*</span>
							<input name="lastname" id="lastname" type="text" class="validate[required,custom[fio_uk]]" value=""></label>
						<label class="col1"><?=tc('First name')?><span class="required">*</span>
							<input name="firstname" id="firstname" type="text" class="validate[required,custom[fio_uk]]" value=""></label>
						<label class="col1"><?=tc('Middle Name')?><span class="required">*</span>
							<input name="middlename" id="middlename" type="text" class="validate[required,custom[fio_uk]]" value=""></label>

						<div class="col1"><?=tc('Gender')?><?
							?><div class="input"><?
							foreach($d['gender_id'] as $id => $v) {
								?><label style="margin-right:15px"><input name="gender" type="radio" value="<?=$id?>"> <?=$v?></label><?
							}
						?></div></div>

						<label class="col1"><?=tc('Birth Year')?>
							<!--<input name="birthday" id="birthday" type="text" class="validate[custom[date],past[NOW],future[1900/01/01]] short" value="">-->
							<select name="birthday" id="birthday">
								<option value=""></option>
									<? for ($i = 1904; $i < date("Y"); $i++) {  ?>
										<option value="01.01.<?=$i?>"><?=$i?></option>
									<? } ?>	
							</select>
						</label>

					</div>

					<h2 class="legend"> <?=tc('Contact data')?> </h2>

					<div class="inner">
						<label class="col1"><?=tc('Index')?><span class="required">*</span>
							<input name="fact_index" id="fact_index" type="text" class="validate[required,custom[integer],minSize[5], maxsize[5]] short" value=""></label>

						<label class="col0"><?=tc('Region, district, town')?><span class="required">*</span>
							<input name="fact_geo_id" id="koatuu" type="text" class="validate[required]"></label>

						<label class="col1"><?=tc('Address')?><span class="required">*</span>
							<input name="fact_address" id="fact_address" type="text" class="validate[required,custom[name_uk]]" value=""></label>

						<div class="row">
							<label class="col3"><?=tc('Контактний телефон')?><br /><?=tc('(код міста, номер)')?>
								<input name="contactphone_pref" id="contactphone_pref" 
										 class="validate[custom[phone_uk],maxSize[5]]" type="text" value="" maxlength="5">
							</label>
							<label class="col4">										 
								<input name="contactphone" id="contactphone" 
										 class="validate[custom[phone_uk],maxSize[9]]" type="text" value="" maxlength="9">
							</label>		 
							
							<label class="col3"><?=tc('Додатковий телефон')?>
								<input name="contactphone2_pref" id="contactphone2_pref" type="text" 
										 class="validate[custom[phone_uk],maxSize[5]]" value="" maxlength="5">
							</label>	
							<label class="col4">										 
								<input name="contactphone2" id="contactphone2" type="text" 
										 class="validate[custom[phone_uk],maxSize[9]]" value="" maxlength="9">
							</label>										 
							
						</div>

					</div>

					<h2 class="legend"> <?=tc('Additional data')?> </h2>

					<div class="inner">
						<label class="col1"><?=tc('Category')?>
						<select name="category_id" id="category_id"><?
							?><option value=""><?=tc('Undefined')?></option><?
							foreach($d['category_id'] as $id => $v) {
								?><option value="<?=$id?>"><?=$v['name']?></option><?
							}
						?></select></label>

						<label class="col1"><?=tc('Social status')?>
						<select name="socialstatus_id" id="socialstatus_id"><?
							?><option value=""><?=tc('Undefined')?></option><?
							foreach($d['socialstatus_id'] as $id => $v) {
								?><option value="<?=$id?>"><?=$v['name']?></option><?
							}
						?></select></label>
					</div>
				</fieldset>

<? startScript(); ?><script type="text/javascript">
	$("#agree").change(function(){$("#register").attr("disabled", !$(this).attr("checked"))});
</script><? endScript(); ?>

				<div class="div-left">
					<label><input type="checkbox" id="agree">
						<?=tc('Згоден з обробкою персональних даних')?>
					</label>
				</div>
				
				<div class="div-right">
					<input type="submit" id="register" name="register" value="<?=htc('Register')?>" disabled>
					<input type="button" name="back" value="<?=tc('Відмінити')?>" 
onclick="if (confirm('<?=htc('При відміні реєстрації будуть втрачені всі введені дані. Ви дійсно бажаєте відмінити реєстрацію?')?>')) location.href = '/'">
				</div>


				
			</form><?
		}

		?><div class="clearer"></div><?
	?></section><?

	unstack();
}
